
#include <stddef.h>
#include <string.h>
#include "MsgBus/internal/MessageQueue.h"

#ifdef __cplusplus
extern "C" {
#endif

	static Message_T* msgBuffer[4];
	static uint8_t msgWriteCount;
	static uint8_t msgReadCount;
	
	//³õÊ¼»¯
	void MsgQueue_Init(void){
		memset(msgBuffer, 0, sizeof(msgBuffer));
		msgWriteCount = 0;
		msgReadCount = 0;
	}
	
	void MsgQueue_Deinit(void){
	
	}
	
	int MsgQueue_Post(Message_T* msg){
		msgBuffer[msgWriteCount++] = msg;
		return 0;
	}
	
	int MsgQueue_Get(Message_T** msg, int ms){
		if(!(msgWriteCount - msgReadCount)){
			return -1;
		}
		*msg = msgBuffer[msgReadCount++];
		return 0;
	}

	typedef unsigned long BPool;
	typedef unsigned int BPoolSize;
	
	static Message_T* msgPoolBase;
	static uint32_t msgPoolCount;
	
	void BPool_Init(BPool *bpool, void *poolSto,
					 uint32_t poolSize, BPoolSize blockSize){
		msgPoolBase = (Message_T*)poolSto;
		msgPoolCount = 0;
	}
	
	void *BPool_Get(BPool *bpool){
		return &msgPoolBase[msgPoolCount++];
	}
	
	void BPool_Put(BPool *bpool, void *b){
		
	}

	
	static uint32_t critical_counter;
	
	void core_util_critical_section_enter(void)
	{
		++critical_counter;
	}
	
	 void core_util_critical_section_exit(void)
	{
		--critical_counter;
	}
#ifdef __cplusplus	 
}
#endif



